Skip to content

Fixes #38561: count no failed rows for a passing == custom SQL test - #38607

Open
mayuriphad wants to merge 8 commits into
open-metadata:mainfrom
mayuriphad:fix/38561-custom-sql-equal-passed-rows
Open

mayuriphad wants to merge 8 commits into
open-metadata:mainfrom
mayuriphad:fix/38561-custom-sql-equal-passed-rows

Conversation

@mayuriphad

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38561

When a tableCustomSQLQuery test with operator == passed, _calculate_passed_rows_success counted the rows the query returned as passed and every other row in the table as failed. The common setup, where the query returns the offending rows and == 0 are expected, therefore reported passedRows = 0 and failedRows = <row count> (100% failed) on a Success result.

This was also inconsistent with the == failure path, which counts the rows in excess of the threshold as failed (len_rows - threshold). A passing == test has no excess, so it now reports failedRows = 0 and passedRows = row_count (or len_rows when no row count is available). The >/>=/</<= branches and all failure paths are unchanged.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • == 0 passing on a 1000-row table (the issue's scenario): 1000 passed, 0 failed.
  • == 10 passing with 10 returned rows: 1000 passed, 0 failed (previously asserted 10 / 990).

Unit tests

  • I added unit tests for the new/changed logic.
  • Files updated: ingestion/tests/unit/observability/data_quality/validations/test_table_custom_sql_query_row_counts.py. Both cases fail on main and pass with the fix. All 64 tests in test_table_custom_sql_query*.py pass locally. On Windows, the sqlite-backed percentage tests also hit WinError 32 errors in teardown that have nothing to do with this change.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (no connector change).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

ruff format --check passes on both files.

UI screen recording:

Not applicable — data quality validator fix, no UI change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

…om SQL test

A tableCustomSQLQuery test with operator == that passed counted the
query's rows as passed and the rest of the table as failed, so == 0
reported 100% failed rows on success. A passing == test has no row in
excess of the threshold, which is what the failure path counts, so it
now reports the whole table as passed.

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
@mayuriphad
mayuriphad requested a review from a team as a code owner November 24, 2026 14:26
@mayuriphad
mayuriphad requested review from akashverma0786 and a balanced review from Copilot November 24, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

…equal-passed-rows

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>

# Conflicts:
#	ingestion/src/metadata/data_quality/validations/table/base/tableCustomSQLQuery.py
Copilot AI balanced review requested due to automatic review settings November 25, 2026 02:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 06:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 07:21
@akashverma0786 akashverma0786 added the safe to test Add this label to run secure Github workflows on PRs label Nov 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…n a non-empty dataset

The pandas empty-dataset test still asserted the old counts (passed=0, failed=3) for a passing == 0 on a three-row table, which is the behaviour this PR fixes.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 11:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@akashverma0786
akashverma0786 enabled auto-merge (squash) November 25, 2026 12:10
…ssing == custom SQL test

The rows a custom SQL query returns are the rows that break the rule, and they are the rows the failed rows sample stores. A passing == now counts them the way < and <= already do: failed = returned rows, passed = the rest. A passing == 0 still reports every row passed and none failed.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

passed_rows = len_rows
failed_rows = (row_count - len_rows) if row_count else 0
elif operator in ("<", "<="):
elif operator in ("<", "<=", "=="):

@Khairajani Khairajani Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing == path still inverts the counts when the query returns fewer rows than the threshold: _calculate_equal_failure sets failed_rows = row_count - len_rows. E.g. == 10, 5 rows returned, 1000-row table → 995 failed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fdb2c07: _calculate_equal_failure now counts abs(len_rows - threshold) as failed and the rest of the table as passed, so == 10 with 5 rows on a 1000-row table gives 5 failed and 995 passed. The row-count and empty-dataset tests are updated for both sides of the threshold (64 passed locally).

…tance from the expected count

A failing == that returned fewer rows than expected counted every row it did not return as failed (== 10 with 5 rows returned on a 1000-row table reported 995 failed). The failed rows are now the rows the result is off by, above or below the expected count, as the more-rows branch, the percentage test and the no-row-count fallback already counted them. A passing == is exactly on the expected count, so it reports no failed rows again.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 13:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Comment on lines +280 to 283
failed_rows = abs(len_rows - threshold)
passed_rows = (row_count - failed_rows) if row_count else 0

return max(0, passed_rows), max(0, failed_rows)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: == failure can report more failed rows than the table has (>100%)

_calculate_equal_failure now sets failed_rows = abs(len_rows - threshold) without a cap. When the expected count is larger than the table (e.g. == 10 on a 5-row table and the query returns 3 rows), you get failedRows = 7 and passedRows = 0. get_test_case_result_object divides by row_count, so failedRowsPercentage comes out as 140%. Before this change, the fewer-rows branch used row_count - len_rows, which never went above the table size. The fix is to cap failed_rows at row_count when a row count is available.

Cap failed rows at the table row count:

failed_rows = abs(len_rows - threshold)
if row_count:
    failed_rows = min(failed_rows, row_count)
    passed_rows = row_count - failed_rows
else:
    passed_rows = 0

return max(0, passed_rows), max(0, failed_rows)
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 🟡 Medium risk 1 closed / 2 findings

Changing equality custom-SQL row accounting may misstate passed/failed row counts for successful or failed checks, affecting interpretation of data-quality results.

Fixes passing == custom SQL tests reporting every non-returned row as failed; a passing == test now reports failedRows = 0 and passedRows = row_count. Open suggestion: when the expected count exceeds the table size, failed_rows in _calculate_equal_failure (tableCustomSQLQuery.py) can exceed row_count, yielding failedRowsPercentage above 100%; capping failed_rows at row_count is recommended.

💡 Edge Case: == failure can report more failed rows than the table has (>100%)

📄 ingestion/src/metadata/data_quality/validations/table/base/tableCustomSQLQuery.py:280-283

_calculate_equal_failure now sets failed_rows = abs(len_rows - threshold) without a cap. When the expected count is larger than the table (e.g. == 10 on a 5-row table and the query returns 3 rows), you get failedRows = 7 and passedRows = 0. get_test_case_result_object divides by row_count, so failedRowsPercentage comes out as 140%. Before this change, the fewer-rows branch used row_count - len_rows, which never went above the table size. The fix is to cap failed_rows at row_count when a row count is available.

Cap failed rows at the table row count
failed_rows = abs(len_rows - threshold)
if row_count:
    failed_rows = min(failed_rows, row_count)
    passed_rows = row_count - failed_rows
else:
    passed_rows = 0

return max(0, passed_rows), max(0, failed_rows)
✅ 1 closed
✅ Edge Case: Passing == N (N>0) now reports 0 failed rows, unlike <= N

📄 ingestion/src/metadata/data_quality/validations/table/base/tableCustomSQLQuery.py:234-241 📄 ingestion/tests/unit/observability/data_quality/validations/test_table_custom_sql_query_row_counts.py:276-287
The new == success branch always sets failedRows = 0 and passedRows = row_count. That is right for == 0, but a passing == 10 whose query returns 10 rows now also reports 0 failed. The <= branch two lines above counts the same 10 returned rows as failed (failed_rows = len_rows), so the same query and result give 10 failed under <= 10 and 0 failed under == 10. Because the failed-rows sample ADR keeps a sample for a Success only when failedRows > 0, a passing == N with N>0 also stops producing a sample. The rewritten test_equal_operator_success asserts 1000/0 and makes this behavior the expected result. To limit the fix to the reported bug, count the returned rows as failed, like <=. That still gives 1000 passed / 0 failed for == 0.

🤖 Prompt for agents
Code Review: Fixes passing `==` custom SQL tests reporting every non-returned row as failed; a passing `==` test now reports `failedRows = 0` and `passedRows = row_count`. Open suggestion: when the expected count exceeds the table size, `failed_rows` in `_calculate_equal_failure` (`tableCustomSQLQuery.py`) can exceed `row_count`, yielding `failedRowsPercentage` above 100%; capping `failed_rows` at `row_count` is recommended.

1. 💡 Edge Case: == failure can report more failed rows than the table has (>100%)
   Files: ingestion/src/metadata/data_quality/validations/table/base/tableCustomSQLQuery.py:280-283

   `_calculate_equal_failure` now sets `failed_rows = abs(len_rows - threshold)` without a cap. When the expected count is larger than the table (e.g. `== 10` on a 5-row table and the query returns 3 rows), you get `failedRows = 7` and `passedRows = 0`. `get_test_case_result_object` divides by `row_count`, so `failedRowsPercentage` comes out as 140%. Before this change, the fewer-rows branch used `row_count - len_rows`, which never went above the table size. The fix is to cap `failed_rows` at `row_count` when a row count is available.

   Fix (Cap failed rows at the table row count):
   failed_rows = abs(len_rows - threshold)
   if row_count:
       failed_rows = min(failed_rows, row_count)
       passed_rows = row_count - failed_rows
   else:
       passed_rows = 0
   
   return max(0, passed_rows), max(0, failed_rows)

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@IceS2 IceS2 assigned IceS2 and unassigned harshsoni2024 Nov 27, 2026

@IceS2 IceS2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mayuriphad, added a small comment. Can you please check it and check the gitar bot one?

Thanks a lot for the contribution

# == counts how far the result is from the expected count as failed (see
# _calculate_equal_failure); a pass is exactly on it, so no row failed.
passed_rows = row_count if row_count else len_rows
failed_rows = 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we count the query matches as failed rows on a passing == check, as we do for <=?

With 10 matches on a 20-row table, == 10 should still succeed and report 10 passed / 10 failed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tableCustomSQLQuery: passing test with operator "==" and threshold 0 reports 100% failed rows

6 participants